// createRouter:创建router实例对象
// createWebHistory:创建history模式路由
import { createRouter, createWebHistory } from 'vue-router'
import Login from '@/views/Login/index.vue'
import Layout from '@/views/Layout/index.vue'
import Home from '@/views/Home/index.vue'
import Category from '@/views/Category/index.vue'
import SubCategory from '@/views/SubCategory/index.vue'
import Deatil from '@/views/Detail/index.vue'
import CartList from '@/views/CartList/index.vue'
import Checkout from '@/views/Ckeckout/index.vue'
import Pay from '@/views/Pay/index.vue'
import PayBack from '@/views/Pay/PayBack.vue'
import User from '@/views/User/index.vue'
import UserInfo from '@/views/User/components/UserInfo.vue'
import UserOrder from '@/views/User/components/UserOrder.vue'




const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
   {
    path: '/',
    component: Layout,
    children:[
      {
        path: '',
        component: Home,
      },
      {
        // 动态路由
        path: 'category/:id',
        component: Category,
      },
      {
        // 动态路由
        path: 'category/sub/:id',
        component: SubCategory,
      },
      {
        // 动态路由
        path: 'detail/:id',
        component: Deatil,
      },
      {
        path: 'cartlist',
        component: CartList
      },
      {
        path: 'ckeckout',
        component: Checkout
      },
      {
        path: 'pay',
        component: Pay
      },
      {
        path: 'paycallback', // 注意路径，必须是paycallback
        component: PayBack
      },
      {
        path: 'user', 
        component: User,
        children:[
          {
            path:'',
            component:UserInfo
          },
          {
            path:'order',
            component:UserOrder
          },
        ]
      }
    ]
   },
   {
    path: '/login',
    component: Login
   },
  ],


  // 路由滚动行为定制
  scrollBehavior(){
    return{
      // 每次切换回顶部
      top:0
    }
  }

})

export default router
